﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using E.Web.UI.Page;
using E.Model;
using X.Common;
using E.BLL;

namespace E.Web.Teacher.internals.skillgroup
{
    public partial class Edit : TeacherBasePage
    {

        public SkillGroup model;
        public int id;
        public string act;
        private CourseBLL bll = new CourseBLL();

        protected override void ShowPage()
        {
            act = XRequest.GetString("act");
            id = XRequest.GetInt("id", -1);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                initUserData();
            }
        }

        protected void btnConfirm_Click(object sender, ImageClickEventArgs e)
        {
            int rst = 0;
            string href = "";

            model = new SkillGroup();
            model.Name = txtName.Text.Trim();

            switch (act)
            {
                case "n":
                    rst = bll.AddSkillGroup(model);
                    href = "/internals/skillgroup/Edit.aspx?act=n";
                    break;
                case "u":
                    model.ID = id;
                    rst = bll.UpdateSkillGroup(model);
                    href = "/internals/skillgroup/Edit.aspx?act=u&id=" + id;
                    break;
                default:
                    break;

            }
            if (rst > 0)
            {
                ExecuteJS("alert('操作成功'); window.location = '" + href + "';");
            }
            else
            {
                Alert("操作失败");
            }
        }

        private void initUserData()
        {
            if (act == "u" && id != -1)
            {
                model = (new CourseBLL()).GetSkillGroupModel(id);
                txtName.Text = model.Name;
            }
        }
    }
}